/**
 *去除字符串前后空格
 *给String对象原型添加trim方法
 */
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 *检测用户名是否存在
 */
function checkUsername() {
    var xmlhttp;
    var username = document.getElementById("username").value;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp == 200) {
            document.getElementById("").innerHTML = xmlhttp.responseText;
        };
    };
    xmlhttp.open("POST", "/order-jsp-servlet/checkUserExist", true);
    xmlhttp.send(username);
    alert(xmlhttp.responseText);
}

/**
 *提交操作
 */
function mySubmit() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var repassword = document.getElementById("repassword").value;
    var realname = document.getElementById("realname").value;

    if (username.trim() == "") {
        var username_tips = document.getElementById("username_tips");
        username_tips.innerHTML = "";
    };
    if (password.trim() == "") {
        var password_tips = document.getElementById("password_tips");
        password_tips.innerHTML = "";
    };
    if (repassword.trim() == "") {
        var repassword_tips = document.getElementById("repassword_tips");
        repassword_tips.innerHTML = "";
    };

    if (realname.trim() == "") {
        var realname_tips = document.getElementById("realname_tips");
        realname_tips.innerHTML = "";
    };
}

/**
 *重置
 */
function reset() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var repassword = document.getElementById("repassword").value;
    var realname = document.getElementById("realname").value;

    username.value = "";
    password.value = "";
    repassword.value = "";
    realname.value = "";
}
